<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/woniu/Public/X-admin/css/x-admin.css" media="all">
</head>
<body>
        <div class="x-body">
            <form class="layui-form layui-form-pane" action="" method="">
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        班级
                    </label>
                    <div class="layui-input-inline">
                       <select name="classty" lay-verify="required" lay-filter="classty">
                          <option value="">--请选择--</option>
                        <?php if(is_array($list)): foreach($list as $key=>$row): ?><option value="<?php echo ($row['id']); ?>"><?php echo ($row['name']); ?></option><?php endforeach; endif; ?>
                       </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        申请人
                    </label>
                    <div class="layui-input-inline">
                       <select name="nameid" lay-verify="required" lay-filter="nameid" id="nameid">
                          <option value="" id="clear">--请选择--</option>                   
                       </select>
                    </div>
                </div>

				<div class="layui-form-item">
				    <label class="layui-form-label">选择类型</label>
				    <div class="layui-input-inline">
				      <select name="type" lay-verify="required" lay-filter="type">
				        <option value="">--请选择--</option>
				        <option value="1">转班</option>
				        <option value="2">转校区</option>
				        <option value="3">见习</option>
				        <option value="4">休学</option>
				        <option value="5">退学</option>
				      </select>
				    </div>				    
				 </div>

				<!-- 默认隐藏选择1转班显示出来 -->
				 <div class="layui-form-item" id="class" style="display:none" >
				 	<label class="layui-form-label">选择班级</label>
				 	<div class="layui-input-inline">
				      <select name="types" lay-filter="class" id="newclass">
                <option value="">--请选择--</option>
				        <?php if(is_array($list)): foreach($list as $key=>$row): ?><option value="<?php echo ($row['id']); ?>" id="new<?php echo ($row['id']); ?>"><?php echo ($row['name']); ?></option><?php endforeach; endif; ?>
				      </select>
				    </div>
				 </div>
        <br>
				<div class="layui-form-item layui-form-text">
				    <label class="layui-form-label">原因</label>
				    <div class="layui-input-block">
				      <textarea id="desc" placeholder="请输入内容" class="layui-textarea"></textarea>
				    </div>
				</div>
        <div class="layui-form-item">
          <div class="layui-input-block" >
              <button class="layui-btn" lay-submit lay-filter="add" style="float:right; margin-right:390px;">申请</button>
          </div>
        </div>                           
      </form>
    </div>
  </body>
</html>
  
   <script src="/woniu/Public/X-admin/lib/layui/layui.js" charset="utf-8"></script>
   <script src="/woniu/Public/X-admin/js/x-layui.js" charset="utf-8"></script>
   <script>
        layui.use(['form','layer'], function(){
              $ = layui.jquery;
              var form = layui.form();
              layer = layui.layer;
              form.on("select(type)",function(data){					
              		if(data.value==1){
              			$("#class").removeAttr("style");
                    $("#newclass").attr("lay-verify","required");
                        // form.render('select');

              		}else{
              			$("#class").attr("style","display:none");
              		}
              		typedata=data.value;
              	});


              
              //监听选择班级下拉框
              form.on("select(classty)",function(data){
                  $("#newclass > option").attr("disabled", false);
                  $("#new"+data.value).attr("disabled", true);
                  $("#clear").nextAll("option").remove();
                  id=data.value;
                  classdata=id;
                  $.ajax({
                      url:"/woniu/index.php/Home/Shift/refer",
                      type:"post",
                      data:{classid:id},
                      dataType:"json",
                      success:
                      function(users){
                        // 获取select
                        select=$("#nameid");
                        for (var i = 0; i < users.length; i++) {
                          // 把遍历出来的数据添加到option
                          info="<option value='"+users[i].id+"'>"+users[i].name+"</option>";
                          // 把当前info数据追加到select
                          select.append(info);
                        }
                        // 更新select渲染
                        form.render('select');
                      }
                  });
              })

              
              form.on("select(class)",function(data){ 
                  classdata=data.value;
              });

              //监听选择学生下拉框
              form.on("select(nameid)",function(data){
                  nameid=data.value;
              })

              //监听提交
              form.on('submit(add)', function(data){
                desc = $("#desc").val();
                $.post('/woniu/index.php/Home/Shift/inserts',{type:typedata,newclass:classdata,desc:desc,nameid:nameid},function(data){
                    if(data=="1"){
                       layer.alert("添加成功", {icon: 6},function () {
                          // 获得frame索引
                          var index = parent.layer.getFrameIndex(window.name);
                          //关闭当前frame
                          parent.layer.close(index);
                          parent.reload();
                       });
                    }else{
                       layer.alert("添加失败", {icon: 6,time:2000},function () {
                            return false;
                       });
                    }
                });
                return false;
            });
        }); 
    </script>